<%@ page contentType="text/html;charset=UTF-8" language="java"  isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2023/3/10
  Time: 10:55
  To change this template use File | Settings | File Templates.
--%>

<%--引入jQuery--%>
<script src="/webjars/jquery/3.6.0/jquery.min.js"></script>
<%--引入bootstrap--%>
<link rel="stylesheet" href="/webjars/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="/webjars/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<html>
<style>
    .table{
        text-align: center;
    }
    .container{
        width: 60%;
    }
</style>
<script>
    $(function () {
        let sid=$("#sid").val()
        // 获取学生ID,根据学生ID是否有值确定标题
        if (sid){
            console.log("sid=",sid)
            $("#title").html("修改学生")
        }else {
            $("#title").html("添加学生")
         <%--console.log("sid=",${param.sid})--%>

    }
    })
    //保存学生
    function save() {
        let sid=$("#sid").val()
        //定义默认路径,默认为添加
        let url="/student/add.do"
        // 如果sid有值则执行修改方法
        if (sid){
            url="/student/update.do"
        }
        //为表单赋值
        document.forms[0].action=url;
        //提交表单
        document.forms[0].submit();
    }
</script>
<head>
    <title>编辑</title>
</head>
<body>
    <div class="container">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <h3 id="title">添加学生</h3>
                </h3>
            </div>
                <form class="form-horizontal" method="post">
                    <input type="hidden" name="sid" id="sid" value="${student.sid}">
                    <div class="form-group">
                        <label for="sname" class="col-sm-2 control-label">学生姓名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="sname" id="sname" value="${student.sname}" placeholder="输入学生姓名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">学生姓名</label>
                        <div class="col-sm-10">
                            <div class="radio">
                                <label>
                                    <input type="radio" name="sex" id="sex1" value="男" ${student.sex=='男'?'checked':''}>男
                                </label>
                                <label>
                                    <input type="radio" name="sex" id="sex2" value="女" ${student.sex=='女'?'checked':''}>女
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="age" class="col-sm-2 control-label">学生年龄</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="age" name="age" value="${student.age}" placeholder="输入学生年龄">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="addr" class="col-sm-2 control-label">学生住址</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="addr" name="addr" value="${student.addr}" placeholder="输入学生住址">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="cid" class="col-sm-2 control-label">所在班级</label>
                        <div class="col-sm-10">
                            <select class="form-control" name="cid" id="cid">
                                <c:forEach items="${classes}" var="c">
                                    <option value="${c.cid}" ${c.cid==student.cid?'selected':''}>${c.cname}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-primary btn-block" onclick="save()">保存</button>
                        </div>
                    </div>
                </form>

            <div class="panel-body text-right">
                右下角文字
            </div>
        </div>
        </div>
    </div>
</body>
</html>
